$(function() {
	load_building_select();
	load_building_cond_select();
	
	_addChangeListener("#building_select", function() {
		var option = $('#building_select option:selected');
		if(view && view.data) {view.data.buildingName = option.text();}
		
		var buildingId = $('#building_select').val();
		
		if(load_floor_select_by_buildingId) {
			load_floor_select_by_buildingId(buildingId);
		}
		
		if(load_floor_checkbox_by_buildingId) {
			load_floor_checkbox_by_buildingId(buildingId);
		}
	});
	
	_addChangeListener("#building_cond_select", function() {
		var buildingId = $('#building_cond_select').val();
		
		if(load_floor_cond_select_by_buildingId) {
			load_floor_cond_select_by_buildingId(buildingId);
		}
		
		if(load_floor_by_buildingId) {
			load_floor_by_buildingId(buildingId);
		}
	});
});

function load_building_select() {
	if($('#building_select').length==0) {return;}

	$('#building_select').html('<option value="" selected></option>');
	$('#floor_select').html('<option value="" selected></option>');
	$('#floor_checkbox').html('');
	$('#room_select').html('<option value="" selected></option>');
	$('#bed_select').html('<option value="" selected></option>');

	findAll_basic(path+'/building/findAll', function(response) {
		for(var i=0; i<response.data.length; i++) {
			$('#building_select').append('<option value="' + response.data[i].buildingId
				+ '">' + response.data[i].buildingName + '</option>');
		}
	});
}

function load_building_cond_select() {
	if($('#building_cond_select').length==0) {return;}

	$('#building_cond_select').html('<option value="" selected></option>');
	$('#floor_cond_select').html('<option value="" selected></option>');
	$('#room_cond_select').html('<option value="" selected></option>');
	$('#bed_cond_select').html('<option value="" selected></option>');
	$('#vue_vm_list div').hide();

	findAll_basic(path+'/building/findAll', function(response) {
		for(var i=0; i<response.data.length; i++) {
			$('#building_cond_select').append('<option value="' + response.data[i].buildingId
				+ '">' + response.data[i].buildingName + '</option>');
		}
	});
}